class Solution
{
public:
    vector<int> canSeePersonsCount(vector<int> &heights)
    {
        stack<int> s;
        for (auto it = heights.rbegin(); it != heights.rend(); ++it)
        {
            int canSeeNum = 0;
            while (!s.empty())
            {
                if (*it > s.top())
                {
                    ++canSeeNum;
                    s.pop();
                }
                else
                {
                    ++canSeeNum;
                    break;
                }
            }
            s.push(*it);
            *it = canSeeNum;
        }
        return heights;
    }
};